{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LAMMPS Tutorials 05. Generate the $\\Sigma5(310)$ Grain Boundary!\n",
    "\n",
    "### Author: Mark Tschopp, mark.a.tschopp.civ at mail.mil\n",
    "\n",
    "Please contact me if you have a problem with this tutorial, so I can modify in Github.  I have added FAQs, and will update my versions of LAMMPS in the future to keep the scripts current.\n",
    "\n",
    "The latest version of this [Jupyter Notebook](http://ipython.org/notebook.html) tutorial is available at https://github.com/mrkllntschpp/lammps-tutorials.\n",
    "\n",
    "The original tutorials are given here: https://icme.hpc.msstate.edu/mediawiki/index.php/LAMMPS_tutorials.  A number of these tutorials are out of date and have been ported over into the current iPython Jupyter Notebook tutorials on github."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Abstract:\n",
    "<a id=\"Sec1\"></a>\n",
    "\n",
    "The objective of this tutorial is to generate a symmetric tilt grain boundary in LAMMPS [1]. This tutorial can serve as a precursor to more advanced techniques, whereby in-plane translations and atom deletion criteria are used to sample a large number of potential structures to find the global minimum energy grain boundary structure [2-3].\n",
    "\n",
    "</br>\n",
    "<table width=\"900\" border=\"0\" cellpadding=\"5\">\n",
    "<tr>\n",
    "\n",
    "<td width=\"250\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/d/d3/Sig5_1.jpg\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "<td width=\"290\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/1/1c/Al_sig5_1.gif\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "<td width=\"290\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/e/e8/Al_sig5_2.gif\" width=\"300\" title=\"Minimization of Sigma5 grain boundary (with different starting position)\">\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "</tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Complete the First Tutorials\n",
    "\n",
    "If you have not done so already, you may want to complete the first four tutorials available [here](https://github.com/mrkllntschpp/lammps-tutorials). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Description of Simulation \n",
    "This LAMMPS [1] molecular dynamics simulation first generates a simulation cell with fcc atoms with two blocks of differing orientations to create the grain boundary: a $<031>$ direction normal to the interface plane (often called grain boundary normal), a $<013>$ direction in the grain boundary plane (y-direction), a shared $<100>$ tilt direction in the z direction. This is a symmetric tilt grain boundary that is known as the $\\Sigma5(310)$ symmetric tilt grain boundary, since both lattices are rotated about a common tilt direction, the $<100>$ direction.  The potential used is the Mishin *et al.* (1999) aluminum potential [4]. The cfg dump files include the x, y, and z coordinates, the centrosymmetry values, the potential energies, and forces for each atom. This can be directly visualized using OVITO [5] and AtomEye [6] visualization tools. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Create the LAMMPS input script \n",
    "This input script was run using the January 2020 version of LAMMPS. The following input script shows how multiple translations and an atom deletion criteria are used to calculate the minimum energy structure. This input script for LAMMPS [1] can be called with a command of the form, `lmp_exe < input.script`. This script contains loops over x-translations, z-translations, and atom overlap distances (an atom is deleted when an atom pair with a nearest neighbor distance is less than this distance). The unique minimum energy structures are saved as a dump file with the energy appended to the filename in a new folder specified by the `gbname` variable. The dump files can then be easily scanned through for the global minimum energy structure. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting in.al_sig5_310_stgb.txt\n"
     ]
    }
   ],
   "source": [
    "%%writefile in.al_sig5_310_stgb.txt\n",
    "\n",
    "# LAMMPS Input File for Grain Boundaries \n",
    "# Mark Tschopp\n",
    "# This file will generate a single Sigma5(310) STGB\n",
    "# Syntax \"lmp_exe < in.al_sig5_310_stgb.txt\" from command prompt\n",
    "\n",
    "\n",
    "# ---------- Initialize Simulation --------------------- \n",
    "clear \n",
    "units metal \n",
    "dimension 3 \n",
    "boundary p p p \n",
    "atom_style atomic \n",
    "\n",
    "# ---------- Create Atomistic Structure --------------------- \n",
    "lattice fcc 4.05 \n",
    "region whole block 0.000000 12.807225 -64.0361225 64.0361225 0.000000 4.050000 units box \n",
    "create_box 2 whole \n",
    "region upper block INF INF 0.000000 64.0361225 INF INF units box \n",
    "lattice fcc 4.05 orient x  0  3  1 orient y  0 -1  3 orient z  1  0  0 \n",
    "create_atoms 1 region upper \n",
    "region lower block INF INF -64.0361225 0.000000 INF INF units box \n",
    "lattice fcc 4.05 orient x  0  3 -1 orient y  0  1  3 orient z  1  0  0 \n",
    "create_atoms 2 region lower \n",
    "group upper type 1 \n",
    "group lower type 2  \n",
    "\n",
    "# ---------- Define Interatomic Potential --------------------- \n",
    "pair_style eam/alloy \n",
    "pair_coeff * * Al99.eam.alloy Al Al\n",
    "neighbor 2.0 bin \n",
    "neigh_modify delay 10 check yes \n",
    " \n",
    "# ---------- Displace atoms and delete overlapping atoms --------------------- \n",
    "displace_atoms upper move 0 0 0 units lattice \n",
    "delete_atoms overlap 0.35 lower upper\n",
    " \n",
    "# ---------- Define Settings --------------------- \n",
    "compute csym all centro/atom fcc\n",
    "compute eng all pe/atom \n",
    "compute eatoms all reduce sum c_eng \n",
    "\n",
    "# ---------- Run Minimization --------------------- \n",
    "reset_timestep 0 \n",
    "thermo 10 \n",
    "thermo_style custom step pe lx ly lz press pxx pyy pzz c_eatoms \n",
    "dump 1 all cfg 25 dump.sig5_minimization_*.cfg mass type xs ys zs c_csym c_eng fx fy fz\n",
    "dump_modify 1 element Al Al\n",
    "min_style cg \n",
    "minimize 1e-15 1e-15 5000 5000 \n",
    "undump 1\n",
    "\n",
    "# ---------- Run Minimization 2--------------------- \n",
    "# Now allow the box to expand/contract perpendicular to the grain boundary\n",
    "reset_timestep 0 \n",
    "thermo 10 \n",
    "thermo_style custom step pe lx ly lz press pxx pyy pzz c_eatoms \n",
    "fix 1 all box/relax y 0 vmax 0.001\n",
    "min_style cg \n",
    "minimize 1e-15 1e-15 5000 5000 \n",
    "\n",
    "# ---------- Calculate GB Energy --------------------- \n",
    "variable minimumenergy equal -3.360000\n",
    "variable esum equal \"v_minimumenergy * count(all)\" \n",
    "variable xseng equal \"c_eatoms - (v_minimumenergy * count(all))\" \n",
    "variable gbarea equal \"lx * lz * 2\" \n",
    "variable gbe equal \"(c_eatoms - (v_minimumenergy * count(all)))/v_gbarea\" \n",
    "variable gbemJm2 equal ${gbe}*16021.7733 \n",
    "variable gbernd equal round(${gbemJm2}) \n",
    "print \"GB energy is ${gbemJm2} mJ/m^2\" \n",
    " \n",
    "# ---------- Dump data into Data file ------------- \n",
    "reset_timestep 0 \n",
    "dump 1 all cfg 10000 dump.al_sig5_310_*.cfg mass type xs ys zs c_csym c_eng fx fy fz\n",
    "dump_modify 1 element Al Al\n",
    "minimize 1e-15 1e-15 5000 5000\n",
    "undump 1\n",
    "\n",
    "write_restart restart.al_sig5_310_stgb\n",
    "\n",
    "print \"All done\" \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So far so good. You should have the file in your working directory if you are running this from Jupyter Notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: Run the LAMMPS Simulation\n",
    "\n",
    "Now run the simulation as we have done before.  On my computer, the 24Jan2020 LAMMPS executable is stored in the `C:\\Program Files\\LAMMPS 64-bit 24Jan2020\\bin\\` folder and is named `lmp_serial.exe`.  The `log.lammps` file should look like the output below. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LAMMPS (24 Jan 2020)\n",
      "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:94)\n",
      "  using 1 OpenMP thread(s) per MPI task\n",
      "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:94)\n",
      "  using 1 OpenMP thread(s) per MPI task\n",
      "Lattice spacing in x,y,z = 4.05 4.05 4.05\n",
      "Created orthogonal box = (0 -64.0361 0) to (12.8072 64.0361 4.05)\n",
      "  1 by 1 by 1 MPI processor grid\n",
      "Lattice spacing in x,y,z = 5.12289 5.12289 4.05\n",
      "Created 200 atoms\n",
      "  create_atoms CPU = 0 secs\n",
      "Lattice spacing in x,y,z = 5.12289 5.12289 4.05\n",
      "Created 200 atoms\n",
      "  create_atoms CPU = 0 secs\n",
      "200 atoms in group upper\n",
      "200 atoms in group lower\n",
      "Displacing atoms ...\n",
      "System init for delete_atoms ...\n",
      "Neighbor list info ...\n",
      "  update every 1 steps, delay 10 steps, check yes\n",
      "  max neighbors/atom: 2000, page size: 100000\n",
      "  master list distance cutoff = 8.28721\n",
      "  ghost atom cutoff = 8.28721\n",
      "  binsize = 4.1436, bins = 4 31 1\n",
      "  2 neighbor lists, perpetual/occasional/extra = 1 1 0\n",
      "  (1) command delete_atoms, occasional\n",
      "      attributes: full, newton on\n",
      "      pair build: full/bin/atomonly\n",
      "      stencil: full/bin/3d\n",
      "      bin: standard\n",
      "  (2) pair eam/alloy, perpetual\n",
      "      attributes: half, newton on\n",
      "      pair build: half/bin/atomonly/newton\n",
      "      stencil: half/bin/3d/newton\n",
      "      bin: standard\n",
      "Deleted 2 atoms, new total = 398\n",
      "WARNING: Using 'neigh_modify every 1 delay 0 check yes' setting during minimization (../min.cpp:178)\n",
      "Neighbor list info ...\n",
      "  update every 1 steps, delay 0 steps, check yes\n",
      "  max neighbors/atom: 2000, page size: 100000\n",
      "  master list distance cutoff = 8.28721\n",
      "  ghost atom cutoff = 8.28721\n",
      "  binsize = 4.1436, bins = 4 31 1\n",
      "  2 neighbor lists, perpetual/occasional/extra = 1 1 0\n",
      "  (1) pair eam/alloy, perpetual\n",
      "      attributes: half, newton on\n",
      "      pair build: half/bin/atomonly/newton\n",
      "      stencil: half/bin/3d/newton\n",
      "      bin: standard\n",
      "  (2) compute centro/atom, occasional\n",
      "      attributes: full, newton on\n",
      "      pair build: full/bin/atomonly\n",
      "      stencil: full/bin/3d\n",
      "      bin: standard\n",
      "Setting up cg style minimization ...\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "Per MPI rank memory allocation (min/avg/max) = 6.915 | 6.915 | 6.915 Mbytes\n",
      "Step PotEng Lx Ly Lz Press Pxx Pyy Pzz c_eatoms \n",
      "       0   -1318.9843    12.807225    128.07225         4.05    875.32429   -2675.7752    7333.2608   -2031.5128   -1318.9843 \n",
      "      10   -1329.8293    12.807225    128.07225         4.05    4863.0678    2399.3262     9226.618    2963.2592   -1329.8293 \n",
      "      20   -1330.1813    12.807225    128.07225         4.05    5739.7373    3277.6653    10380.205    3561.3418   -1330.1813 \n",
      "      30    -1330.212    12.807225    128.07225         4.05    5799.4078    3324.6136    10511.649    3561.9611    -1330.212 \n",
      "      40   -1330.2137    12.807225    128.07225         4.05    5823.0131    3345.3792    10560.649    3563.0112   -1330.2137 \n",
      "      50   -1330.2144    12.807225    128.07225         4.05    5832.2375    3357.8939    10569.301    3569.5176   -1330.2144 \n",
      "      60   -1330.2146    12.807225    128.07225         4.05    5829.3139    3356.4392    10559.179    3572.3232   -1330.2146 \n",
      "      70   -1330.2147    12.807225    128.07225         4.05    5826.5788     3359.271    10546.817    3573.6486   -1330.2147 \n",
      "      80   -1330.2148    12.807225    128.07225         4.05    5827.0603    3369.2954    10538.855     3573.031   -1330.2148 \n",
      "      90   -1330.2149    12.807225    128.07225         4.05    5827.8483    3370.9088    10540.535    3572.1008   -1330.2149 \n",
      "     100   -1330.2149    12.807225    128.07225         4.05    5827.4309    3370.2637    10540.434    3571.5951   -1330.2149 \n",
      "     110   -1330.2149    12.807225    128.07225         4.05    5827.2641     3370.103      10540.1    3571.5894   -1330.2149 \n",
      "     120   -1330.2149    12.807225    128.07225         4.05    5827.1959    3370.2252    10539.733    3571.6293   -1330.2149 \n",
      "     130   -1330.2149    12.807225    128.07225         4.05    5827.2147    3370.2646    10539.782    3571.5977   -1330.2149 \n",
      "     140   -1330.2149    12.807225    128.07225         4.05    5827.2184    3370.2754     10539.79    3571.5902   -1330.2149 \n",
      "     150   -1330.2149    12.807225    128.07225         4.05    5827.2245    3370.2865    10539.797    3571.5901   -1330.2149 \n",
      "     160   -1330.3065    12.807225    128.07225         4.05    5486.4599    3278.2877    10150.296    3030.7963   -1330.3065 \n",
      "     170   -1331.2971    12.807225    128.07225         4.05    2994.3413    1573.5922    6198.1222    1211.3096   -1331.2971 \n",
      "     180   -1332.3795    12.807225    128.07225         4.05    671.53228   -229.29146    2556.3365   -312.44823   -1332.3795 \n",
      "     190   -1332.6867    12.807225    128.07225         4.05     476.4523   -550.75108    2300.0801   -319.97209   -1332.6867 \n",
      "     200    -1332.831    12.807225    128.07225         4.05    522.24045    -590.7736    2470.1978   -312.70285    -1332.831 \n",
      "     210   -1332.8982    12.807225    128.07225         4.05    611.85773   -500.48038    2617.0088   -280.95519   -1332.8982 \n",
      "     220   -1333.1697    12.807225    128.07225         4.05    374.71373   -431.28845    2161.1616   -605.73201   -1333.1697 \n",
      "     230   -1333.2825    12.807225    128.07225         4.05    241.73628   -500.73441    1923.3922   -697.44897   -1333.2825 \n",
      "     240   -1333.5182    12.807225    128.07225         4.05   -232.58898   -709.56238    952.58755   -940.79211   -1333.5182 \n",
      "     250   -1333.5563    12.807225    128.07225         4.05   -223.40056   -691.90797    1042.4711   -1020.7648   -1333.5563 \n",
      "     260   -1333.5631    12.807225    128.07225         4.05   -220.00444   -678.97811    1049.1839   -1030.2191   -1333.5631 \n",
      "     270   -1333.5693    12.807225    128.07225         4.05   -232.19076   -699.23929    1011.4353   -1008.7683   -1333.5693 \n",
      "     280   -1333.5737    12.807225    128.07225         4.05   -221.28441    -679.0167    1035.0484   -1019.8849   -1333.5737 \n",
      "     290   -1333.5752    12.807225    128.07225         4.05   -222.73332   -685.48633    1040.1408   -1022.8544   -1333.5752 \n",
      "     300   -1333.5761    12.807225    128.07225         4.05   -225.76133   -690.32883    1028.4035   -1015.3586   -1333.5761 \n",
      "     310   -1333.5765    12.807225    128.07225         4.05    -216.5128   -668.88209    1036.0761   -1016.7324   -1333.5765 \n",
      "     320   -1333.5765    12.807225    128.07225         4.05   -210.95686   -655.94426    1042.1759   -1019.1022   -1333.5765 \n",
      "     330   -1333.5765    12.807225    128.07225         4.05   -209.64904   -653.91437    1044.4036   -1019.4363   -1333.5765 \n",
      "     340   -1333.5765    12.807225    128.07225         4.05   -208.22229   -650.91456    1046.0722   -1019.8245   -1333.5765 \n",
      "     350   -1333.5765    12.807225    128.07225         4.05   -207.93651   -650.31068    1046.1522   -1019.6511   -1333.5765 \n",
      "     360   -1333.5832    12.807225    128.07225         4.05   -46.082338   -299.48509    1141.3696   -980.13153   -1333.5832 \n",
      "     370    -1333.598    12.807225    128.07225         4.05     2.814388   -213.45894    1147.5665   -925.66444    -1333.598 \n",
      "     380   -1333.6008    12.807225    128.07225         4.05   -3.7100332   -224.48996    1149.4868   -936.12694   -1333.6008 \n",
      "     390   -1333.6017    12.807225    128.07225         4.05   -6.4041484   -244.61824    1177.4563   -952.05049   -1333.6017 \n",
      "     400    -1333.602    12.807225    128.07225         4.05    -5.919032   -248.20595    1190.1268   -959.67795    -1333.602 \n",
      "     410   -1333.6022    12.807225    128.07225         4.05   -5.9478967   -252.92227    1193.0505   -957.97195   -1333.6022 \n",
      "     420   -1333.6024    12.807225    128.07225         4.05   -6.0073039   -257.46429    1193.2288   -953.78645   -1333.6024 \n",
      "     430   -1333.6024    12.807225    128.07225         4.05   -6.2551038   -260.23057    1194.4389   -952.97366   -1333.6024 \n",
      "     440   -1333.6024    12.807225    128.07225         4.05    -5.961906   -262.50531     1199.828   -955.20844   -1333.6024 \n",
      "     450   -1333.6024    12.807225    128.07225         4.05   -6.3132957   -263.18379    1199.4195   -955.17561   -1333.6024 \n",
      "     460   -1333.6024    12.807225    128.07225         4.05   -6.3238846   -262.72081      1198.67   -954.92083   -1333.6024 \n",
      "     470   -1333.6024    12.807225    128.07225         4.05   -6.3097866   -262.60999     1198.379   -954.69834   -1333.6024 \n",
      "     480   -1333.6024    12.807225    128.07225         4.05   -6.3293985   -262.49635     1198.113   -954.60487   -1333.6024 \n",
      "     490   -1333.6024    12.807225    128.07225         4.05   -6.3231618   -262.49418    1198.2104   -954.68568   -1333.6024 \n",
      "     500   -1333.6024    12.807225    128.07225         4.05   -6.3320316   -262.43614    1198.1402   -954.70018   -1333.6024 \n",
      "     510   -1333.6024    12.807225    128.07225         4.05   -6.3230727   -262.39102    1198.1323   -954.71046   -1333.6024 \n",
      "     520   -1333.6024    12.807225    128.07225         4.05   -6.3238323   -262.35909    1198.0613   -954.67368   -1333.6024 \n",
      "     530   -1333.6024    12.807225    128.07225         4.05   -6.3248734   -262.36595    1198.0672   -954.67585   -1333.6024 \n",
      "     540   -1333.6024    12.807225    128.07225         4.05   -6.3244058   -262.36682    1198.0701   -954.67649   -1333.6024 \n",
      "     542   -1333.6024    12.807225    128.07225         4.05   -6.3244998   -262.36715    1198.0707   -954.67709   -1333.6024 \n",
      "Loop time of 1.85895 on 1 procs for 542 steps with 398 atoms\n",
      "\n",
      "84.1% CPU use with 1 MPI tasks x 1 OpenMP threads\n",
      "\n",
      "Minimization stats:\n",
      "  Stopping criterion = energy tolerance\n",
      "  Energy initial, next-to-last, final = \n",
      "        -1318.98429985     -1333.60243409     -1333.60243409\n",
      "  Force two-norm initial, final = 17.5886 3.5972e-06\n",
      "  Force max component initial, final = 6.25036 7.71654e-07\n",
      "  Final line search alpha, max atom move = 1 7.71654e-07\n",
      "  Iterations, force evaluations = 542 1053\n",
      "\n",
      "MPI task timing breakdown:\n",
      "Section |  min time  |  avg time  |  max time  |%varavg| %total\n",
      "---------------------------------------------------------------\n",
      "Pair    | 1.562      | 1.562      | 1.562      |   0.0 | 84.03\n",
      "Neigh   | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Comm    | 0.078185   | 0.078185   | 0.078185   |   0.0 |  4.21\n",
      "Output  | 0.21873    | 0.21873    | 0.21873    |   0.0 | 11.77\n",
      "Modify  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Other   |            | 0          |            |       |  0.00\n",
      "\n",
      "Nlocal:    398 ave 398 max 398 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Nghost:    5281 ave 5281 max 5281 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Neighs:    27742 ave 27742 max 27742 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "FullNghs:  55464 ave 55464 max 55464 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "\n",
      "Total # of neighbors = 55464\n",
      "Ave neighs/atom = 139.357\n",
      "Neighbor list builds = 3\n",
      "Dangerous builds = 0\n",
      "WARNING: Using 'neigh_modify every 1 delay 0 check yes' setting during minimization (../min.cpp:178)\n",
      "Setting up cg style minimization ...\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "WARNING: Energy due to 3 extra global DOFs will be included in minimizer energies\n",
      "Per MPI rank memory allocation (min/avg/max) = 5.643 | 5.643 | 5.643 Mbytes\n",
      "Step PotEng Lx Ly Lz Press Pxx Pyy Pzz c_eatoms \n",
      "       0   -1333.6024    12.807225    128.07225         4.05   -6.3244998   -262.36715    1198.0707   -954.67709   -1333.6024 \n",
      "      10    -1333.605    12.807225    128.20639         4.05   -828.09491   -880.61698    1.8270866   -1605.4948    -1333.605 \n",
      "      20   -1333.6051    12.807225    128.20707         4.05   -831.38992   -883.93412   0.56664804   -1610.8023   -1333.6051 \n",
      "      30   -1333.6051    12.807225    128.20732         4.05   -833.09063   -886.44194    0.3824404   -1613.2124   -1333.6051 \n",
      "      40   -1333.6051    12.807225    128.20747         4.05   -833.61346   -886.80269   0.52447525   -1614.5622   -1333.6051 \n",
      "      50   -1333.6051    12.807225    128.20747         4.05   -833.84518    -887.1478   0.49809131   -1614.8858   -1333.6051 \n",
      "      60   -1333.6051    12.807225     128.2076         4.05    -834.5071    -888.1867   0.71014815   -1616.0448   -1333.6051 \n",
      "      70   -1333.6051    12.807225    128.20776         4.05   -835.20649   -888.92423   0.36195128   -1617.0572   -1333.6051 \n",
      "      80   -1333.6051    12.807225    128.20777         4.05    -835.3125    -889.2479    0.2428944   -1616.9325   -1333.6051 \n",
      "      90   -1333.6051    12.807225    128.20781         4.05    -835.5732   -889.34644   0.36205835   -1617.7352   -1333.6051 \n",
      "     100   -1333.6051    12.807225    128.20771         4.05   -834.54225   -888.64244    2.3949654   -1617.3793   -1333.6051 \n",
      "     110   -1333.6051    12.807225    128.20778         4.05   -835.33731   -889.48679   0.97251177   -1617.4977   -1333.6051 \n",
      "     120   -1333.6051    12.807225    128.20787         4.05   -835.90827   -889.93806  -0.01581355   -1617.7709   -1333.6051 \n",
      "     130   -1333.6051    12.807225    128.20789         4.05    -836.0196   -890.09788 -0.063898329    -1617.897   -1333.6051 \n",
      "     140   -1333.6051    12.807225    128.20791         4.05   -836.17823   -890.25233    -0.095853   -1618.1865   -1333.6051 \n",
      "     150   -1333.6051    12.807225    128.20792         4.05   -836.22913   -890.22555  -0.13264324   -1618.3292   -1333.6051 \n",
      "     160   -1333.6051    12.807225    128.20793         4.05   -836.26194   -890.18045  -0.19783941   -1618.4075   -1333.6051 \n",
      "     170   -1333.6051    12.807225      128.208         4.05   -836.51542   -890.43546  -0.31628362   -1618.7945   -1333.6051 \n",
      "     180   -1333.6051    12.807225    128.20811         4.05    -837.0378   -891.07092  -0.54002464   -1619.5024   -1333.6051 \n",
      "     190   -1333.6051    12.807225    128.20765         4.05   -834.08819   -889.52234    4.4212353   -1617.1635   -1333.6051 \n",
      "     200   -1333.6051    12.807225    128.20794         4.05    -836.3773   -890.93805   0.33708847   -1618.5309   -1333.6051 \n",
      "     210   -1333.6051    12.807225    128.20792         4.05   -836.33954   -890.95449   0.33973151   -1618.4039   -1333.6051 \n",
      "     220   -1333.6051    12.807225    128.20794         4.05    -836.4529   -891.13335   0.30257101   -1618.5279   -1333.6051 \n",
      "     230   -1333.6051    12.807225    128.20797         4.05   -836.56385   -891.22985   0.21847733   -1618.6802   -1333.6051 \n",
      "     240   -1333.6051    12.807225    128.20798         4.05   -836.54165   -891.14523   0.15485666   -1618.6346   -1333.6051 \n",
      "     250   -1333.6051    12.807225    128.20798         4.05   -836.46659   -891.04741   0.12842261   -1618.4808   -1333.6051 \n",
      "     260   -1333.6051    12.807225      128.208         4.05   -836.51692   -891.15868   0.10485006   -1618.4969   -1333.6051 \n",
      "     270   -1333.6051    12.807225    128.20802         4.05   -836.65216   -891.31092  0.068814139   -1618.7144   -1333.6051 \n",
      "     280   -1333.6051    12.807225    128.20799         4.05   -836.54499    -891.0697  0.082595506   -1618.6479   -1333.6051 \n",
      "     290   -1333.6051    12.807225    128.20793         4.05    -836.3411    -890.9096  0.069093671   -1618.1828   -1333.6051 \n",
      "     300   -1333.6051    12.807225    128.20795         4.05   -836.46788   -891.27584  0.060835978   -1618.1886   -1333.6051 \n",
      "     310   -1333.6051    12.807225    128.20804         4.05   -836.75293   -891.39949  0.054431343   -1618.9137   -1333.6051 \n",
      "     320   -1333.6051    12.807225    128.20803         4.05   -836.71951   -891.32202  0.069045968   -1618.9055   -1333.6051 \n",
      "     330   -1333.6051    12.807225    128.20802         4.05   -836.70441   -891.46095  0.084862286   -1618.7371   -1333.6051 \n",
      "     340   -1333.6051    12.807225    128.20803         4.05   -836.74066   -891.51771    0.0880788   -1618.7924   -1333.6051 \n",
      "     350   -1333.6051    12.807225    128.20799         4.05    -836.5811   -891.36002  0.094270588   -1618.4775   -1333.6051 \n",
      "     360   -1333.6051    12.807225    128.20799         4.05    -836.6055    -891.4794  0.090994741   -1618.4281   -1333.6051 \n",
      "     370   -1333.6051    12.807225    128.20799         4.05   -836.61605   -891.42838  0.097017984   -1618.5168   -1333.6051 \n",
      "     380   -1333.6051    12.807225    128.20801         4.05   -836.67233    -891.3785   0.12605792   -1618.7645   -1333.6051 \n",
      "     390   -1333.6051    12.807225    128.20804         4.05   -836.79405   -891.60132    0.1094652   -1618.8903   -1333.6051 \n",
      "     400   -1333.6051    12.807225    128.20805         4.05   -836.86176   -891.79394   0.12428002   -1618.9156   -1333.6051 \n",
      "     410   -1333.6051    12.807225    128.20806         4.05   -836.94074   -891.95987   0.09254123   -1618.9549   -1333.6051 \n",
      "     420   -1333.6051    12.807225    128.20807         4.05   -837.00758   -892.08383   0.11061352   -1619.0495   -1333.6051 \n",
      "     430   -1333.6051    12.807225    128.20805         4.05   -836.91623   -891.97134   0.11765658    -1618.895   -1333.6051 \n",
      "     440   -1333.6051    12.807225    128.20806         4.05    -836.9784   -892.17536   0.10912795    -1618.869   -1333.6051 \n",
      "     450   -1333.6051    12.807225    128.20806         4.05    -837.0054   -892.30593    0.1122969   -1618.8226   -1333.6051 \n",
      "     460   -1333.6051    12.807225    128.20805         4.05   -836.97397   -892.21409  0.080032572   -1618.7879   -1333.6051 \n",
      "     470   -1333.6051    12.807225    128.20806         4.05   -837.03399   -892.28174     0.080132   -1618.9004   -1333.6051 \n",
      "     480   -1333.6051    12.807225    128.20806         4.05    -837.0459   -892.31041  0.070819253   -1618.8981   -1333.6051 \n",
      "     490   -1333.6051    12.807225    128.20807         4.05   -837.06291    -892.3886  0.078851736    -1618.879   -1333.6051 \n",
      "     500   -1333.6051    12.807225    128.20808         4.05   -837.14433   -892.52639  0.071651704   -1618.9782   -1333.6051 \n",
      "     510   -1333.6051    12.807225     128.2081         4.05    -837.1927   -892.52569  0.052496365   -1619.1049   -1333.6051 \n",
      "     520   -1333.6051    12.807225     128.2081         4.05   -837.22991   -892.54909  0.044025815   -1619.1847   -1333.6051 \n",
      "     530   -1333.6051    12.807225    128.20811         4.05   -837.22936   -892.56439  0.044083479   -1619.1678   -1333.6051 \n",
      "     540   -1333.6051    12.807225    128.20811         4.05   -837.22455   -892.55322  0.048460227   -1619.1689   -1333.6051 \n",
      "     550   -1333.6051    12.807225     128.2081         4.05   -837.22482   -892.55808  0.046905326   -1619.1633   -1333.6051 \n",
      "     560   -1333.6051    12.807225    128.20809         4.05   -837.19272    -892.5571  0.054981283    -1619.076   -1333.6051 \n",
      "     570   -1333.6051    12.807225    128.20809         4.05   -837.19368      -892.58  0.044210259   -1619.0452   -1333.6051 \n",
      "     580   -1333.6051    12.807225    128.20809         4.05   -837.20026   -892.59662  0.043622891   -1619.0478   -1333.6051 \n",
      "     590   -1333.6051    12.807225    128.20809         4.05   -837.20432   -892.60343  0.044973585   -1619.0545   -1333.6051 \n",
      "     600   -1333.6051    12.807225     128.2081         4.05   -837.21192   -892.60288  0.047758035   -1619.0806   -1333.6051 \n",
      "     610   -1333.6051    12.807225     128.2081         4.05   -837.21271   -892.59277  0.050311613   -1619.0957   -1333.6051 \n",
      "     620   -1333.6051    12.807225     128.2081         4.05   -837.21648   -892.59406   0.05379737   -1619.1092   -1333.6051 \n",
      "     630   -1333.6051    12.807225     128.2081         4.05   -837.23166   -892.60856  0.054550887    -1619.141   -1333.6051 \n",
      "     640   -1333.6051    12.807225     128.2081         4.05   -837.23555   -892.60564  0.053016867    -1619.154   -1333.6051 \n",
      "     650   -1333.6051    12.807225     128.2081         4.05   -837.22217   -892.59102  0.061528025    -1619.137   -1333.6051 \n",
      "     660   -1333.6051    12.807225     128.2081         4.05   -837.22397   -892.60214  0.060926328   -1619.1307   -1333.6051 \n",
      "     670   -1333.6051    12.807225     128.2081         4.05   -837.22835   -892.61499    0.0615845   -1619.1316   -1333.6051 \n",
      "Loop time of 3.03053 on 1 procs for 670 steps with 398 atoms\n",
      "\n",
      "68.6% CPU use with 1 MPI tasks x 1 OpenMP threads\n",
      "\n",
      "Minimization stats:\n",
      "  Stopping criterion = energy tolerance\n",
      "  Energy initial, next-to-last, final = \n",
      "        -1333.60243409     -1333.60506881     -1333.60506881\n",
      "  Force two-norm initial, final = 4.96749 0.000302454\n",
      "  Force max component initial, final = 4.96749 0.000255344\n",
      "  Final line search alpha, max atom move = 1 0.000255344\n",
      "  Iterations, force evaluations = 670 1339\n",
      "\n",
      "MPI task timing breakdown:\n",
      "Section |  min time  |  avg time  |  max time  |%varavg| %total\n",
      "---------------------------------------------------------------\n",
      "Pair    | 2.187      | 2.187      | 2.187      |   0.0 | 72.17\n",
      "Neigh   | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Comm    | 0.046894   | 0.046894   | 0.046894   |   0.0 |  1.55\n",
      "Output  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Modify  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Other   |            | 0.7966     |            |       | 26.29\n",
      "\n",
      "Nlocal:    398 ave 398 max 398 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Nghost:    5233 ave 5233 max 5233 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Neighs:    27721 ave 27721 max 27721 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "FullNghs:  55464 ave 55464 max 55464 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "\n",
      "Total # of neighbors = 55464\n",
      "Ave neighs/atom = 139.357\n",
      "Neighbor list builds = 0\n",
      "Dangerous builds = 0\n",
      "GB energy is 567.570396456139 mJ/m^2\n",
      "WARNING: Using 'neigh_modify every 1 delay 0 check yes' setting during minimization (../min.cpp:178)\n",
      "Setting up cg style minimization ...\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "WARNING: Energy due to 3 extra global DOFs will be included in minimizer energies\n",
      "Per MPI rank memory allocation (min/avg/max) = 6.924 | 6.924 | 6.924 Mbytes\n",
      "Step PotEng Lx Ly Lz Press Pxx Pyy Pzz c_eatoms \n",
      "       0   -1333.6051    12.807225     128.2081         4.05   -837.22835   -892.61499  0.061584499   -1619.1316   -1333.6051 \n",
      "      10   -1333.6051    12.807225    128.20811         4.05   -837.26755   -892.63121 -0.006637773   -1619.1648   -1333.6051 \n",
      "      17   -1333.6051    12.807225    128.20811         4.05   -837.30073   -892.65955 -0.067032171   -1619.1756   -1333.6051 \n",
      "Loop time of 0.062511 on 1 procs for 17 steps with 398 atoms\n",
      "\n",
      "100.0% CPU use with 1 MPI tasks x 1 OpenMP threads\n",
      "\n",
      "Minimization stats:\n",
      "  Stopping criterion = energy tolerance\n",
      "  Energy initial, next-to-last, final = \n",
      "        -1333.60506881     -1333.60506882     -1333.60506882\n",
      "  Force two-norm initial, final = 0.000302683 0.00028078\n",
      "  Force max component initial, final = 0.000255615 0.000278226\n",
      "  Final line search alpha, max atom move = 1 0.000278226\n",
      "  Iterations, force evaluations = 17 34\n",
      "\n",
      "MPI task timing breakdown:\n",
      "Section |  min time  |  avg time  |  max time  |%varavg| %total\n",
      "---------------------------------------------------------------\n",
      "Pair    | 0.062511   | 0.062511   | 0.062511   |   0.0 |100.00\n",
      "Neigh   | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Comm    | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Output  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Modify  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Other   |            | 0          |            |       |  0.00\n",
      "\n",
      "Nlocal:    398 ave 398 max 398 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Nghost:    5227 ave 5227 max 5227 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Neighs:    27721 ave 27721 max 27721 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "FullNghs:  55442 ave 55442 max 55442 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "\n",
      "Total # of neighbors = 55442\n",
      "Ave neighs/atom = 139.302\n",
      "Neighbor list builds = 0\n",
      "Dangerous builds = 0\n",
      "System init for write_restart ...\n",
      "All done\n",
      "Total wall time: 0:00:05\n"
     ]
    }
   ],
   "source": [
    "!\"C:/Program Files/LAMMPS 64-bit 24Jan2020/bin/lmp_serial\" < in.al_sig5_310_stgb.txt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The grain boundary energy is calculated as 567.57 mJ/m$^2$. The final configuration is stored in a restart file for future use in predicting properties of grain boundaries. Additionally, files with atomic coordinates, energies, and centrosymmetry values are dumped for post-processing. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Step 3: Making the Deformation Movie \n",
    "\n",
    "Not much postprocessing to do with this example, so try making a few movies like explained in  [Tutorial 3](LAMMPS-Tutorials-03.ipynb) and [Tutorial 4](LAMMPS-Tutorials-04.ipynb).\n",
    "\n",
    "Figure 1 shows a movie of minimization of the grain boundary structure for the input script show above. To see the effect of changing the starting position, Figure 2 shows a movie of minimization of the grain boundary structure for a modification of the input script above. Here, the \n",
    "\n",
    "</br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "delete_atoms overlap 0.35 lower upper\n",
    "</div>\n",
    "\n",
    "line in the input script has been modified to \n",
    "\n",
    "</br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "delete_atoms overlap 1.5 lower upper\n",
    "</div>\n",
    "\n",
    "This eliminates two atoms that are too close to each other near the grain boundary interface (shown in Figure 4).  Interestingly, this simple example shows that the grain boundary energy landscape can be very complex due to a number of different energy minima, which can only be accessed through broadly sampling the grain boundary design space.\n",
    "\n",
    "</br>\n",
    "<table width=\"800\" border=\"0\" cellpadding=\"5\">\n",
    "<tr>\n",
    "\n",
    "<td width=\"290\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/1/1c/Al_sig5_1.gif\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "  <figcaption><strong>Figure 1.</strong> Movie showing the minimization of the grain boundary structure for an aluminum $\\Sigma5(310)$ symmetric tilt grain boundary. </figcaption>\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "<td width=\"290\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/e/e8/Al_sig5_2.gif\" width=\"300\" title=\"Minimization of Sigma5 grain boundary (with different starting position)\">\n",
    "    <figcaption><strong>Figure 2.</strong> Movie showing the minimization of the grain boundary structure for an aluminum $\\Sigma5(310)$ symmetric tilt grain boundary (with a slightly different starting position, e.g., \"delete_atoms overlap 1.5 lower upper\"). </figcaption>\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "</tr>\n",
    "</table>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 3 shows the image corresponding to the input script shown above. Notice how there are two atoms that are very close to each other at the boundary in Figure 3 (shown in red, colored by potential energy, i.e., high energy atoms). The final structures are shown in Figures 4 and 5 for the input script above and the modified input script, respectively. Interestingly, with this potential, the structure in Figure 4 is actually the lower energy grain boundary structure (567.57 mJ/m$^2$ in Figure 4 compared to 576.12 mJ/m$^2$ in Figure 5). The different structures for this one simple grain boundary may impart slightly different properties as well. Often, the convention is to use the minimum energy grain boundary structure for properties. However, some recent research has also explored metastable higher energy grain boundary structures and their impact on properties as well. \n",
    "\n",
    "\n",
    "<table width=\"800\" border=\"0\" cellpadding=\"5\">\n",
    "<tr>\n",
    "\n",
    "<td width=\"250\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/f/fa/Sig5_0.jpg\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "  <figcaption><strong>Figure 3.</strong> Image showing the grain boundary structure prior to minimization. </figcaption>\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "<td width=\"250\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/d/d3/Sig5_1.jpg\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "  <figcaption><strong>Figure 4.</strong> Image showing the grain boundary structure after minimization (overlap distance equals 0.35). </figcaption>\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "<td width=\"250\" align=\"center\" valign=\"center\">\n",
    "<figure>\n",
    "  <img src=\"https://icme.hpc.msstate.edu/mediawiki/images/9/91/00016.jpg\" width=\"300\" title=\"Minimization of Sigma5 grain boundary\">\n",
    "  <figcaption><strong>Figure 5.</strong> Image showing the grain boundary structure after minimization (overlap distance equals 1.50). </figcaption>\n",
    "</figure>\n",
    "</td>\n",
    "\n",
    "</tr>\n",
    "</table>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## FAQs \n",
    "\n",
    "</br>\n",
    "<div class=\"alert alert-danger\">\n",
    "    <strong>Question 1</strong>: Why does the asymmetric grain boundary structure the lower energy?  \n",
    "</div>\n",
    "\n",
    "First, this result will be a function of the interatomic potential and the grain boundary configuration.  It just happens that the minimum energy $\\Sigma5(310)$ grain boundary structure with this aluminum potential is asymmetric.  Others may not be so.  It should also be noted that the difference between the two structures is less than 10 mJ/m$^2$, so both may be observed in experiments at finite temperatures."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Links\n",
    "\n",
    "* [Click here to open Tutorial 1](LAMMPS-Tutorials-01.ipynb)\n",
    "* [Click here to open Tutorial 2](LAMMPS-Tutorials-02.ipynb)\n",
    "* [Click here to open Tutorial 3](LAMMPS-Tutorials-03.ipynb)\n",
    "* [Click here to open Tutorial 4](LAMMPS-Tutorials-04.ipynb)\n",
    "* [Click here to open the next tutorial](LAMMPS-Tutorials-06.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## References \n",
    "\n",
    "1. S. Plimpton, \"Fast Parallel Algorithms for Short-Range Molecular Dynamics,\" J. Comp. Phys., 117, 1-19 (1995). \n",
    "1. Tschopp, M. A., & McDowell, D.L. (2007). Structures and energies of Sigma3 asymmetric tilt grain boundaries in Cu and Al. Philosophical Magazine, 87, 3147-3173 (http://dx.doi.org/10.1080/14786430701455321). \n",
    "1. Tschopp, M. A., & McDowell, D.L. (2007). Asymmetric tilt grain boundary structure and energy in copper and aluminum. Philosophical Magazine, 87, 3871-3892 (http://dx.doi.org/10.1016/j.commatsci.2010.02.003).\n",
    "1. Y. Mishin, D. Farkas, M.J. Mehl, and D.A. Papaconstantopoulos, \"Interatomic potentials for monoatomic metals from experimental data and ab initio calculations,\" Phys. Rev. B 59, 3393 (1999). \n",
    "1. A. Stukowski, \"Visualization and analysis of atomistic simulation data with OVITO – the Open Visualization Tool,\" Modelling Simul. Mater. Sci. Eng. 18 (2010) 015012.\n",
    "1. J. Li, \"AtomEye: an efficient atomistic configuration viewer,\" Modelling Simul. Mater. Sci. Eng. 11 (2003) 173. "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
